package file;

import java.io.File;
import java.io.FileFilter;

public class ListFilesDemo {
    public static void main(String[] args) {
        /*File file = new File(".");
        if(file.isDirectory()){
            File[] files = file.listFiles();
            System.out.println(files.length);
            for(File dirs : files){
                System.out.println(dirs.getName());
            }
        }*/
        File file = new File(".");
        if(file.isDirectory()){
            FileFilter filter = new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    return pathname.getName().endsWith(".txt");
                }
            };
            File[] files = file.listFiles(filter);
            System.out.println(files.length);
        }
    }
}
